package net.xdclass.controller;


import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.xdclass.request.LoginRequest;
import net.xdclass.request.UserRegisterRequest;
import net.xdclass.service.FileUploadService;
import net.xdclass.service.UserService;
import net.xdclass.util.JsonData;
import net.xdclass.vo.UserVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 二当家小D
 * @since 2021-03-12
 */
@Api(tags = "用户模块")
@RestController
@RequestMapping("/api/user/v1")
public class UserController {

    @Autowired
    private FileUploadService fileUploadService;

    @Autowired
    private UserService userService;

    @ApiOperation("上传头像")
    @PostMapping("/uploadHead")
    public JsonData uploadHead(HttpServletRequest request,
                               @RequestParam(value = "FILE",required = true) MultipartFile file) {
        return fileUploadService.uploadHead(request, file);
    }

    @ApiOperation("注册用户")
    @PostMapping("/registerUser")
    public JsonData registerUser(@RequestBody UserRegisterRequest userRegisterRequest){
        return userService.registerUser(userRegisterRequest);
    }

    @ApiOperation("登录")
    @PostMapping("/login")
    public JsonData login(@RequestBody LoginRequest loginRequest){
        return userService.login(loginRequest);
    }

    @ApiOperation("查询用户的详细信息")
    @GetMapping("/findUserDetail")
    public JsonData findUserDetail(){
        UserVo userDetail = userService.findUserDetail();
        return JsonData.buildSuccess(userDetail);
    }
}

